/**
 * @author zym
 * @namespace code/module
 * @requires
 */
define([ 'ko', 'platform.common', 'titleview', 'bs.table', 'bs.tree',
		'bs.validator' ], function(ko, platform, titleview) {
	return {
		_enabled : ko.observable(false),
		code_id : ko.observable(),
		code_value : ko.observable(),
		code_text : ko.observable(),
		p_code_id : ko.observable(),
		edit_status : ko.observable('0'),
		$form : $('detailForm'),
		$modal : $('#codeModal'),
		initForm : function() {
			this.code_id(platform.uuid());
			this.edit_status('0');
			this._enabled(true);
		},
		resetForm : function() {
			if (this.$form.data('bootstrapValidator') != null
					|| $form.data('bootstrapValidator') != undefined) {
				$form.data('bootstrapValidator').resetForm();
			}
		},
		validateForm : function() {
			this.$form.bootstrapValidator({
				message : 'This value is not valid',
				feedbackIcons : {
					valid : 'glyphicon glyphicon-ok',
					invalid : 'glyphicon glyphicon-remove',
					validating : 'glyphicon glyphicon-refresh'
				},
				excluded : [ ':disabled' ],
				fields : {
					code_value : {
						validators : {
							notEmpty : {
								message : '码值为必填字段,不可为空'
							}
						}
					},
					code_text : {
						validators : {
							notEmpty : {
								message : '中文释义为必填字段,不可为空'
							}
						}
					}
				}
			});
		},
		clear : function() {
			this._enabled(false);
			this.code_id();
			this.code_value();
			this.code_text();
			this.p_code_id();
			this.edit_status();
		},
		showNewForm : function(str) {
			this.clear();
			this.initForm();
			titleview.title('公共码表新增');
			if (str != undefined) {
				this.p_code_id(str);
			}
			this.validateForm();
			this._enabled(true);
			this.$modal.modal('show');
		},
		showEditForm : function(pid) {
			var result = methods.get(pid);
			this.clear();
			this.validateForm();
			this.code_id(result.code_id);
			this.code_value(result.code_value);
			this.code_text(result.code_text);
			this._enabled(true);
			this.edit_status('1');
            titleview.title('公共码表编辑');
			this.$modal.modal('show');
		}
	}
});